import _motor


def pwm_init() -> _motor.PWM:
    pwm = _motor.PWM()
    pwm.setPin('PA8')
    pwm.setFreq(50)
    pwm.setDuty(0.5)
    pwm.enable()
    return pwm


class Motor:
    def __init__(self) -> None:
        self._pwm = pwm_init()
        self.move(0)

    def move(self, angle):
        # 2.5ms -> 180
        # 0.5ms -> 0
        # circle -> 20ms
        # duty -> 0 ~ 1
        angle = 180 - angle
        time = 0.5 + angle / 180 * 2
        duty = time / 20
        self._pwm.setDuty(duty)
